//
//  WKMeViewController.m
//  WKDemo
//
//  Created by wangzhaohui-Mac on 14-8-11.
//  Copyright (c) 2014年 com.app. All rights reserved.
//

#import "WKMeViewController.h"
#import "WKComposeViewController.h"
#import "WKCollectionViewController.h"
#import "WKSettingViewController.h"
#import "WKCommonArrowItem.h"
#import "WKCommonGroup.h"
#import "WKCommonCell.h"


@interface WKMeViewController ()
@property (nonatomic,strong) NSMutableArray *groups;

@property (nonatomic,strong) WKCollectionViewController *conllectVc;
@end

@implementation WKMeViewController
#pragma mark - 懒加载
- (NSMutableArray *)groups
{
    if (_groups == nil) {
        _groups = [NSMutableArray array];
    }
    return _groups;
}
/**
 *  拦截初始化，改变tableViewCell的样式
 */
- (id)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.tableView.y = 10;

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.title = @"未登录";
    
    [self setupBUtton];
   
    //设置tableView头部视图的高度
    self.tableView.sectionHeaderHeight = 0;
    self.tableView.sectionFooterHeight = 10;
    //设置tableView的内边距
    self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
    //取消tableView的分割线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView.backgroundColor = WKGlobalBg;
    
    //设置导航栏左侧按钮
    [self setupNavigationBarButtonItem];
    
    //初始化模型数据
    [self setupGroups];
}
/**
 *  初始化模型数据
 */
- (void)setupGroups
{
    [self setupGroup0];
    [self setupGroup1];

}
- (void)setupGroup0
{
    WKCommonGroup *group = [WKCommonGroup group];
    
    [self.groups addObject:group];
   
    WKCommonArrowItem *item1 = [WKCommonArrowItem itemWithTitel:@"请登录" icon:@"placeholderImage2"];
    group.items = @[item1];
    
}

- (void)setupGroup1
{
    WKCommonGroup *group = [WKCommonGroup group];
    [self.groups addObject:group];
    WKCommonArrowItem *item0 = [WKCommonArrowItem itemWithTitel:@"好友动态"];
    WKCommonArrowItem *item1 = [WKCommonArrowItem itemWithTitel:@"推荐关注"];
   
    group.items = @[item0,item1];
    
}

- (void)setupBUtton
{
    //设置tableView的底部视图
    WKCollectionViewController *collectVc = [[WKCollectionViewController alloc] init];
    self.conllectVc = collectVc;
   collectVc.view.frame = CGRectMake(0, 0, 320, 300);

    self.tableView.tableFooterView = collectVc.view;
}


/**设置导航栏左右侧按钮*/
- (void)setupNavigationBarButtonItem
{
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemImageName:@"navigationButtonPublish" highlightImage:@"navigationButtonPublishClick" target:self action:@selector(leftCompile)];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemImageName:@"mine-setting-icon" highlightImage:@"mine-setting-icon-click" target:self action:@selector(setting)];
}

- (void)leftCompile
{
    WKComposeViewController *composeVc = [[WKComposeViewController alloc] init];
    
    //以模态的形式弹出发帖控制器
    //    [self.navigationController presentModalViewController:composeVc animated:YES];//次方法已经过时
    
    [self.navigationController presentViewController:composeVc animated:NO completion:^{
        
    }];
}

- (void)setting
{
    WKSettingViewController *setingVC = [[WKSettingViewController alloc] init];
    
    [self.navigationController pushViewController:setingVC animated:YES];
}

#pragma mark - TableView data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return self.groups.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    WKCommonGroup *group = self.groups[section];
    
    return group.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WKCommonCell *cell = [WKCommonCell cellWithTableView:tableView];
    WKCommonGroup *group = self.groups[indexPath.section];
    cell.item = group.items[indexPath.row];
    // 设置cell所处的行号 和 所处组的总行数
    [cell setIndexPath:indexPath rowInSection:group.items.count];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 44;
    
}

@end
